package com.panshi.controller.leave;

import com.panshi.api.ILeaveApi;
import com.panshi.po.LeavePO;
import com.panshi.vo.DeleteLeaveVO;
import com.panshi.vo.UpdateLeaveVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 用户留言修改
 */
@Controller
@Slf4j
public class UpdateLeaveController {

    @Autowired
    private ILeaveApi leaveApi;


    /**
     * 根据id获取用户信息，跳转页面
     * @param id
     * @param model
     * @return
     */
    @GetMapping("updatelea")
    public String updatelea(@RequestParam Integer id, Model model){

      LeavePO leavePO= leaveApi.queryIdAttnLeavePostBody(id).getData();
        log.info("leavePO==========={}",leavePO);
        model.addAttribute("leavePO",leavePO);
        return "leave/leave-update";
    }

    /**
     * 修改信息
     * @param updateLeaveVO
     * @return
     */
    @PostMapping("leave-updateLeave")
    @ResponseBody
    public Map<String,Object> updateLeave(UpdateLeaveVO updateLeaveVO){

        log.info("updateLeaveVO========={}",updateLeaveVO);
        Map<String,Object> map = new HashMap<>();
        updateLeaveVO.setFeedbackdate(new Date());

      Integer integer=  leaveApi.updateLeavePostBody(updateLeaveVO).getData();

        if(integer == 0){
            map.put("success",false);
            map.put("message","修改失败，请重新修改");
        }else if(integer == 1){
            map.put("success",true);
            map.put("message","修改成功");
        }
        return map;
    }

    /*@PostMapping("leave-deleteLeave")
    @ResponseBody
    public Map<String,Object> deleteLeave(DeleteLeaveVO deleteLeaveVO){
        log.info("deleteLeaveVO========={}",deleteLeaveVO);
        Map<String,Object> map = new HashMap<>();
        deleteLeaveVO.setUpdatedate(new Date());
     Integer integer=   leaveApi.deleteLeavePostBody(deleteLeaveVO).getData();
        if(integer == 0){
            map.put("success",false);
            map.put("message","删除失败，请重新删除");
        }else if(integer == 1){
            map.put("success",true);
            map.put("message","删除成功");
        }

        return map;
    }*/

}
